<?php
declare(ENCODING = 'utf-8');

/*
 * CR_ItemManager.php created on 14 avr. 08 
 * Author: Rodrigue Le Gall
 * 
 * This file is inspired by the project Typo3
 *
 * RPortal is an open source web based Content Management System
 * Copyright (C) 2002-2008  Rodrigue Le Gall
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * ItemManager holds the new and modified nodes with Sessionscope
 *
 * @package CR
 */
class CR_ItemManager implements CR_ItemManagerInterface {

	/**
	 * @var array Nodes
	 */
	protected $nodes;

	/**
	 * Constructs a Node
	 *
	 * @return void
	 */
	public function __construct() {
		$this->nodes = array();
	}

	/**
	 * Create the Node in nodes.
	 *
	 * @param phpCR_NodeInterface		the node for add
	 * @return void
	 */
	public function addNode(phpCR_NodeInterface $node) {
		$this->nodes[$node->getUUID()] = $node;
	}

	/**
	 * get nodes as a NodeIterator
	 *
	 * @return phpCR_NodeIteratorInterface the nodes
	 * @todo How to remove an Item?
	 */
	public function getNodes() {

		if (count($this->nodes)===0) {
			return NULL;
		}

		foreach ($this->nodes as $node) {
			if (($node->isModified() === FALSE) && ($node->isNew() === FALSE)) unset($this->nodes[$node->getUUID()]);
		}

		return $this->nodes;
	}

}
